package com.jinglin.admin.controller;

import com.jinglin.controller.ABaseController;
import com.jinglin.entity.po.CategoryInfo;
import com.jinglin.entity.vo.ResponseVO;
import com.jinglin.service.CategoryInfoService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController extends ABaseController {
    @Autowired
    private CategoryInfoService categoryInfoService;
    @RequestMapping("/loadCategory")
    public ResponseVO getLoadCategory(){
        List<CategoryInfo> list = categoryInfoService.getCategoryList();
        return getSuccessResponseVO(list);
    }
    @RequestMapping("/saveCategory")
    public ResponseVO addCategory(CategoryInfo categoryInfo){
        categoryInfoService.saveCategory(categoryInfo);
        return getSuccessResponseVO(true);
    }
    @RequestMapping("/delCategory")
    public ResponseVO delCategory(@RequestParam("categoryId")String categoryId){
        categoryInfoService.delCategory(categoryId);
        return getSuccessResponseVO(true);
    }
    @RequestMapping("/changeSort")
    public ResponseVO changeSort(@Param("pCategoryId")String pCategoryId,@Param("categoryIds")String categoryIds){
        // 前端传来的categoryIds是已经排序好的分类顺序
        categoryInfoService.changeSort(pCategoryId,categoryIds);
        return getSuccessResponseVO(true);
    }

}
